﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Login : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btLogin_Click(object sender, EventArgs e)
    {
        try
        {
            string vCode = checkCode.Text;
            string vCode1 = Session["Vnumber"].ToString();
            if (vCode.CompareTo(vCode1) !=0)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('验证码输入错误')", true);
            }
            else
            {
                DbAccess db = new DbAccess();
                string uid = userId.Text;
                if (uid == string.Empty)
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('用户名不能为空')", true);
                }
                else
                {
                    string upwd = Md5.getMd5(password.Text);//获取MD5加密后的字符串
                    string sql = "select uid,pwd from UserInfo where uid='" + uid + "' and pwd='" + upwd + "'";
                    DataSet dsUser = db.GetDataSet(sql);
                    if (dsUser.Tables[0].Rows.Count > 0)//登录成功
                    {
                        Session["user"] = uid;
                    }
                    else//登录失败
                    {
                        Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('用户名密码错误')", true);
                    }
                }
            }
        }
        catch
        { 
        
        }
    }
    protected void btReg_Click(object sender, EventArgs e)
    {
        Response.Redirect("Register.aspx");
    }
}
